﻿//<TunynetCopyright>
//--------------------------------------------------------------
//<copyright>青岛拓宇网络科技有限公司 2005-2008</copyright>
//<version>V0.5</verion>
//<createdate>2008-2-22</createdate>
//<author>zhengw</author>
//<email>zhengw@tunynet.com</email>
//<log date="2008-2-22">创建</log>
//--------------------------------------------------------------
//</TunynetCopyright>

using System;
using System.Collections.Generic;
using System.Text;

namespace ChinaCustoms.Qingdao.Workflow.Supports
{
    /// <summary>
    /// 活动实例实体类
    /// </summary>
    [Serializable]
    public class ActivityInstanceInfo : ActivityPrototypeInfo
    {
        /// <summary>
        /// 空参数构造函数
        /// </summary>
        public ActivityInstanceInfo()
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="activityPrototype"><see cref="ActivityPrototypeInfo"/></param>
        public ActivityInstanceInfo(ActivityPrototypeInfo activityPrototype)
        {
            this.ActivityGuid = Guid.NewGuid();
            this.Status = ActivityStatus.Executing;
            this.ActivityLevel = activityPrototype.ActivityLevel;
            this.WorkflowGuid = activityPrototype.WorkflowGuid;
            this.SubFlowGuid = activityPrototype.SubFlowGuid;
            this.PrototypeGuid = activityPrototype.PrototypeGuid;
            this.ActivityName = activityPrototype.ActivityName;
            this.CodeName = activityPrototype.CodeName;
            this.Description = activityPrototype.Description;
            this.UrlOfWorkItem = activityPrototype.UrlOfWorkItem;

            this.AllowPostil = activityPrototype.AllowPostil;
            this.AllowRedesignateExecutor = activityPrototype.AllowRedesignateExecutor;

            if (!string.IsNullOrEmpty(activityPrototype.RequiredDepartmentIDs))
                this.RequiredDepartmentIDs = activityPrototype.RequiredDepartmentIDs;

            this.RequiredRelativeDepartment = activityPrototype.RequiredRelativeDepartment;

            if (!string.IsNullOrEmpty(activityPrototype.RequiredRoles))
                this.RequiredRoles = activityPrototype.RequiredRoles;

            if (!string.IsNullOrEmpty(activityPrototype.RequiredUserGroups))
                this.RequiredUserGroups = activityPrototype.RequiredUserGroups;

            if (activityPrototype.AllowRedesignateExecutor)
                this.RequiredUserNames = activityPrototype.RequiredUserNames;

            if (!string.IsNullOrEmpty(activityPrototype.ActivityCodeNamesForJump))
                this.ActivityCodeNamesForJump = activityPrototype.ActivityCodeNamesForJump;

            this.AllowBack = activityPrototype.AllowBack;

            this.AllowFinalJudgment = activityPrototype.AllowFinalJudgment;

            if (activityPrototype.IsSubFlow)
            {
                this.IsSubFlow = true;
                this.OnlyShowRelativeTopLevelInOrganizationSelectorOfSubFlow = activityPrototype.OnlyShowRelativeTopLevelInOrganizationSelectorOfSubFlow;
                this.RequireFeedbackInSubFlow = activityPrototype.RequireFeedbackInSubFlow;
                
                //this.RequireFeedbackInSubFlow = activityPrototype.RequireFeedbackInSubFlow;
                this.CorrelativeSubFlowGuid = activityPrototype.CorrelativeSubFlowGuid;
            }
            else
            {
                this.IsSubFlow = false;
            }
        }


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="activityPrototype"><see cref="ActivityPrototypeInfo"/></param>
        public ActivityInstanceInfo(ActivityInstanceInfo activityInstance)
        {
            this.ActivityGuid = Guid.NewGuid();
            this.Status = ActivityStatus.Executing;            
            this.ActivityLevel = activityInstance.ActivityLevel;
            this.WorkflowGuid = activityInstance.WorkflowGuid;
            this.SubFlowGuid = activityInstance.SubFlowGuid;
            this.SubTaskGuid = activityInstance.SubTaskGuid;
            this.PrototypeGuid = activityInstance.PrototypeGuid;
            this.ActivityName = activityInstance.ActivityName;
            this.CodeName = activityInstance.CodeName;
            this.Description = activityInstance.Description;
            this.UrlOfWorkItem = activityInstance.UrlOfWorkItem;

            this.AllowPostil = activityInstance.AllowPostil;
            this.AllowRedesignateExecutor = activityInstance.AllowRedesignateExecutor;

            if (!string.IsNullOrEmpty(activityInstance.RequiredDepartmentIDs))
                this.RequiredDepartmentIDs = activityInstance.RequiredDepartmentIDs;

            this.RequiredRelativeDepartment = activityInstance.RequiredRelativeDepartment;

            if (!string.IsNullOrEmpty(activityInstance.RequiredRoles))
                this.RequiredRoles = activityInstance.RequiredRoles;

            if (!string.IsNullOrEmpty(activityInstance.RequiredUserGroups))
                this.RequiredUserGroups = activityInstance.RequiredUserGroups;

            if (activityInstance.AllowRedesignateExecutor)
                this.RequiredUserNames = activityInstance.RequiredUserNames;

            if (!string.IsNullOrEmpty(activityInstance.ActivityCodeNamesForJump))
                this.ActivityCodeNamesForJump = activityInstance.ActivityCodeNamesForJump;

            this.AllowBack = activityInstance.AllowBack;

            this.AllowFinalJudgment = activityInstance.AllowFinalJudgment;

            if (activityInstance.IsSubFlow)
            {
                this.IsSubFlow = true;

                this.OnlyShowRelativeTopLevelInOrganizationSelectorOfSubFlow = activityInstance.OnlyShowRelativeTopLevelInOrganizationSelectorOfSubFlow;
                this.RequireFeedbackInSubFlow = activityInstance.RequireFeedbackInSubFlow;
                this.CorrelativeSubFlowGuid = activityInstance.CorrelativeSubFlowGuid;
                this.ActivityGuidOfStartThisSubFlowActivity = activityInstance.ActivityGuidOfStartThisSubFlowActivity;
            }
            else
            {
                this.IsSubFlow = false;
            }
        }


        private Guid activityGuid;
        /// <summary>
        /// 活动GUID
        /// </summary>
        public Guid ActivityGuid
        {
            get { return this.activityGuid; }
            set { this.activityGuid = value; }
        }


        private Guid subTaskGuid = Guid.Empty;
        /// <summary>
        /// 子任务GUID
        /// </summary>
        public Guid SubTaskGuid
        {
            get { return this.subTaskGuid; }
            set { this.subTaskGuid = value; }
        }


        private ActivityStatus status = ActivityStatus.Creating;
        /// <summary>
        /// 活动状态
        /// </summary>
        public ActivityStatus Status
        {
            get { return this.status; }
            set { this.status = value; }
        }

        private DateTime createDate;
        /// <summary>
        /// 创建日期
        /// </summary>
        public DateTime CreateDate
        {
            get { return this.createDate; }
            set { this.createDate = value; }
        }

    }
}
